import pygame
from pygame.locals import *

class WorldView:

    def __init__(self, world):
        self.black  = (0, 0, 0)
        self.yellow = (255, 255, 0)
        self.size   = 4

        self.world = world
        self.w     = self.world.w * self.size
        self.h     = self.world.h * self.size

        pygame.init()
        pygame.display.set_mode((self.w, self.h), DOUBLEBUF | HWSURFACE)
        pygame.display.set_caption('Celula')
        pygame.display.set_icon(pygame.image.load('glider.png'))
        self.screen = pygame.display.get_surface()

    def draw(self):
        self.screen.fill(self.black)
        for x in range(self.world.w):
            for y in range(self.world.h):
                if self.world.cells[x][y]:
                    rect = pygame.Rect(
                        (x * self.size, y * self.size),
                        (self.size, self.size)
                    )
                    pygame.draw.rect(self.screen, self.yellow, rect, 0)
        pygame.display.flip()
